unit Class_MovTabl;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TMovTabl=class(TUniEngine)  
  public
    TablIdex: Integer;
    TablName: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class function  CopyIt(AMovTabl:TMovTabl):TMovTabl;overload;        
    class procedure CopyIt(AMovTabl:TMovTabl;var Result:TMovTabl);overload;       
  end;

implementation

{ TMovTabl }
procedure TMovTabl.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('TABL_IDEX').Value := TABLIDEX;
        ParamByName('TABL_NAME').Value := TABLNAME; 
      end;
      otEdit:
      begin
        ParamByName('TABL_IDEX').Value := TABLIDEX;
        ParamByName('TABL_NAME').Value := TABLNAME; 
      end;  
      otDelt:
      begin
        ParamByName('TABL_IDEX').Value := TABLIDEX;
 
      end;  
    end;
  end;
end;

function TMovTabl.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_MOVTABL',['TABL_IDEX',TABLIDEX],AUniConnection);
end;

function TMovTabl.GetNextIdex: Integer;
begin

end;

function TMovTabl.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TMovTabl.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_MOVTABL WHERE   TABL_IDEX=:TABL_IDEX';
end;

function TMovTabl.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_MOVTABL'
         +'    ( TABL_IDEX, TABL_NAME)'
         +'    VALUES'
         +'    (:TABL_IDEX,:TABL_NAME)';
end;

function TMovTabl.GetStrsIndex: string;
begin
  Result:=Format('%S',[TablName]);
end;

function TMovTabl.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_MOVTABL SET'
         +'    TABL_NAME=:TABL_NAME'
         +'    WHERE TABL_IDEX=:TABL_IDEX';
end;

constructor TMovTabl.Create;
begin

end;

destructor TMovTabl.Destroy;
begin

  inherited;
end;

class function TMovTabl.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TMovTabl.Create;
  with TMovTabl(Result) do
  begin
    TABLIDEX:=AUniQuery.FieldByName('TABL_IDEX').AsInteger;
    TABLNAME:=AUniQuery.FieldByName('TABL_NAME').AsString;
  end;  
end;

class function  TMovTabl.CopyIt(AMovTabl: TMovTabl): TMovTabl;
begin
  Result:=TMovTabl.Create;
  Result.TABLIDEX:=AMovTabl.TABLIDEX;
  Result.TABLNAME:=AMovTabl.TABLNAME;
end;

class procedure TMovTabl.CopyIt(AMovTabl:TMovTabl;var Result:TMovTabl);
begin
  if Result=nil then Exit;
  Result.TABLIDEX:=AMovTabl.TABLIDEX;
  Result.TABLNAME:=AMovTabl.TABLNAME;
end;

end.

